cmake build system: visiblity support for clang
[supercollider.git] / Help / UGens / Synth control / Demand Rate / Dbufwr.html
blob56d13d1158d648ed0626d51414eba9248a538ebc
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="824.44">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #ad140d}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #001bb9}
16 span.s1 {font: 18.0px Helvetica}
17 span.s2 {font: 9.0px Monaco}
18 span.s3 {text-decoration: underline ; color: #002fe0}
19 span.s4 {color: #001bb9}
20 span.s5 {color: #ad140d}
21 span.s6 {color: #000000}
22 span.Apple-tab-span {white-space:pre}
23 </style>
24 </head>
25 <body>
26 <p class="p1"><span class="s1"><b>Dbufwr</b></span><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><b> buffer demand ugen</b></p>
27 <p class="p2"><br></p>
28 <p class="p1">superclass: DUGen</p>
29 <p class="p3"><br></p>
30 <p class="p3"><br></p>
31 <p class="p1"><b>*new(input, bufnum, phase, loop)</b></p>
32 <p class="p3"><br></p>
33 <p class="p1">all inputs can be either demand ugen or any other ugen.</p>
34 <p class="p3"><br></p>
35 <p class="p1"><b>input</b><span class="Apple-tab-span"> </span>single channel input</p>
36 <p class="p1"><b>bufnum</b><span class="Apple-tab-span"> </span>buffer number to read from (single channel buffer)</p>
37 <p class="p1"><b>phase</b><span class="Apple-tab-span"> </span>index into the buffer</p>
38 <p class="p1"><b>loop</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>when phase exceeds number of frames in buffer, loops when set to 1 (default :1)</p>
39 <p class="p3"><br></p>
40 <p class="p1">see also [<a href="Dbufrd.html"><span class="s3">Dbufrd</span></a>]</p>
41 <p class="p2"><span class="Apple-tab-span"> </span></p>
42 <p class="p2"><br></p>
43 <p class="p4">// alloc a single channel buffer</p>
44 <p class="p5">b = <span class="s4">Buffer</span>.alloc(s, 24, 1);</p>
45 <p class="p5">b.setn(0, { 210 } ! b.numFrames);</p>
46 <p class="p2"><br></p>
47 <p class="p4">// post some info:</p>
48 <p class="p5">fork { loop { 0.5.wait; b.getn(0, b.numFrames, {<span class="s4">|x|</span> x.postln }) } };</p>
49 <p class="p2"><br></p>
50 <p class="p4">// write demand sequence into a buffer</p>
51 <p class="p5">(</p>
52 <p class="p5">{</p>
53 <p class="p5"><span class="s4">var</span> read, write, readpos, writepos, writetrig;</p>
54 <p class="p2"><br></p>
55 <p class="p5"><span class="Apple-tab-span"> </span>writetrig = <span class="s4">Dust</span>.kr(1);</p>
56 <p class="p5"><span class="Apple-tab-span"> </span>readpos = <span class="s4">Dseries</span>(0, 1, <span class="s4">inf</span>);</p>
57 <p class="p5"><span class="Apple-tab-span"> </span>writepos = <span class="s4">Dseq</span>([<span class="s4">Dseries</span>(0, 3, 30), <span class="s4">Dseries</span>(0, 1, 30)], <span class="s4">inf</span>);</p>
58 <p class="p2"><br></p>
59 <p class="p5"><span class="Apple-tab-span"> </span>read = <span class="s4">Dbufrd</span>(b, readpos);</p>
60 <p class="p5"><span class="Apple-tab-span"> </span>write = <span class="s4">Dbufwr</span>(<span class="s4">Dseq</span>([<span class="s4">Dseries</span>(1, 1, 16), <span class="s4">Dwhite</span>(1, 16, 8)], <span class="s4">inf</span>) * 60, b, writepos);</p>
61 <p class="p2"><br></p>
62 <p class="p5"><span class="Apple-tab-span"> </span><span class="s4">Demand</span>.kr(writetrig, 0, write); <span class="s5">// write on trigger</span></p>
63 <p class="p2"><br></p>
64 <p class="p6"><span class="s6"><span class="Apple-tab-span"> </span></span>SinOsc<span class="s6">.ar(</span></p>
65 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Demand</span>.kr(<span class="s4">Impulse</span>.kr(16), 0, read).lag(0.01) * [1, 1.01]</p>
66 <p class="p5"><span class="Apple-tab-span"> </span>) * 0.1</p>
67 <p class="p2"><br></p>
68 <p class="p5">}.play;</p>
69 <p class="p5">)</p>
70 <p class="p2"><br></p>
71 <p class="p2"><br></p>
72 <p class="p2"><br></p>
73 <p class="p4">// write into buffer with mouse clicks</p>
74 <p class="p5">(</p>
75 <p class="p5">{</p>
76 <p class="p4"><span class="s6"><span class="Apple-tab-span"> </span></span><span class="s4">var</span><span class="s6"> val = </span><span class="s4">MouseY</span><span class="s6">.kr(1000, 200, 1); </span>// cursor y pos controls frequency</p>
77 <p class="p4"><span class="s6"><span class="Apple-tab-span"> </span></span><span class="s4">var</span><span class="s6"> pos = </span><span class="s4">MouseX</span><span class="s6">.kr(0, </span><span class="s4">BufFrames</span><span class="s6">.kr(b) - 1); </span>// cursor x position controls buffer pos</p>
78 <p class="p4"><span class="s6"><span class="Apple-tab-span"> </span></span><span class="s4">var</span><span class="s6"> write = </span><span class="s4">MouseButton</span><span class="s6">.kr; </span>// button controls write action</p>
79 <p class="p5"><span class="Apple-tab-span"> </span><span class="s4">Demand</span>.kr(write, 0, <span class="s4">Dbufwr</span>(val, b, pos, 1));</p>
80 <p class="p6"><span class="s6"><span class="Apple-tab-span"> </span></span>SinOsc<span class="s6">.ar(</span></p>
81 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">Duty</span>.kr(<span class="s4">Dseq</span>([0.5, 0.75, 0.5, 1.0], <span class="s4">inf</span>) * 0.2, 0, <span class="s4">Dbufrd</span>(b, <span class="s4">Dseries</span>(0, 1, <span class="s4">inf</span>)))</p>
82 <p class="p5"><span class="Apple-tab-span"> </span>) * 0.1</p>
83 <p class="p5">}.play;</p>
84 <p class="p5">)</p>
85 <p class="p2"><br></p>
86 <p class="p2"><br></p>
87 <p class="p2"><br></p>
88 <p class="p2"><br></p>
89 <p class="p2"><br></p>
90 <p class="p2"><br></p>
91 <p class="p4">// write demand sequence into a buffer</p>
92 <p class="p5">b.free; b = <span class="s4">Buffer</span>.alloc(s, 2, 1);</p>
93 <p class="p5">fork { loop { 0.5.wait; b.getn(0, b.numFrames, {<span class="s4">|x|</span> x.postln }) } };</p>
94 <p class="p5">b.setn(0, [1, 0]);</p>
95 <p class="p2"><br></p>
96 <p class="p5">(</p>
97 <p class="p5">{</p>
98 <p class="p5"><span class="s4">var</span> read, write, readpos, writepos, writetrig;</p>
99 <p class="p2"><br></p>
100 <p class="p5"><span class="Apple-tab-span"> </span>writetrig = <span class="s4">Impulse</span>.kr(2);</p>
101 <p class="p4"><span class="s6"><span class="Apple-tab-span"> </span>readpos = </span><span class="s4">Dbufrd</span><span class="s6">(b, 1); </span>// first buffer val is position</p>
102 <p class="p4"><span class="s6"><span class="Apple-tab-span"> </span>writepos = </span><span class="s4">Dbufrd</span><span class="s6">(b, 0); </span>// second buffer val is position</p>
103 <p class="p5"><span class="Apple-tab-span"> </span>read = <span class="s4">Dbufrd</span>(b, readpos);</p>
104 <p class="p2"><br></p>
105 <p class="p5"><span class="Apple-tab-span"> </span>write = <span class="s4">Dbufwr</span>(read, b, writepos);</p>
106 <p class="p2"><br></p>
107 <p class="p5"><span class="Apple-tab-span"> </span><span class="s4">Demand</span>.kr(writetrig, 0, write); <span class="s5">// write on trigger</span></p>
108 <p class="p5">}.play;</p>
109 <p class="p5">)</p>
110 <p class="p2"><br></p>
111 <p class="p2"><br></p>
112 <p class="p4">// free buffer:</p>
113 <p class="p5">b.free;</p>
114 <p class="p2"><br></p>
115 <p class="p2"><br></p>
116 <p class="p2"><br></p>
117 <p class="p2"><br></p>
118 <p class="p2"><br></p>
119 <p class="p2"><br></p>
120 </body>
121 </html>